module.exports =  function access(type){
  return function(data){
    const { socket: { id }, ctx  } = this; 
    if(!ctx[id]) return
    let content = ctx[id].user.name
    if(type === 'entry'){
      content += '加入了冲浪'
    } else if(type === 'quit'){
      content += '离开了冲浪'
    } else if(type === 'disconnect'){
      delete ctx[id]
      content += '下线了'
    }
    this.room({
      id,
      userName: '系统',
      content,
      createAt: new Date(),
      type: 'sys',
    })
    //在线人数
    this.io.emit('pull', {
      type: 'online',
      data: {
        number: Object.keys(ctx).length
      },
    })
  }
}
